package org.jash.shop2202.shop

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import dagger.hilt.android.AndroidEntryPoint
import org.jash.shop2202.R
import org.jash.shop2202.databinding.ActivityShopBinding
import org.jash.shop2202.mvvm.BaseActivity
import org.jash.shop2202.mvvm.BaseViewModel
import org.jash.shop2202.utils.Event
@AndroidEntryPoint
@Route(path = "/shop/main")
class ShopActivity : BaseActivity<ActivityShopBinding, BaseViewModel>() {
    override fun initData() {

    }

    override fun initView() {
        binding.navigation.setOnItemSelectedListener {
            supportFragmentManager.beginTransaction().replace(R.id.container, ARouter.getInstance().build(when(it.itemId) {
                R.id.category -> "/shop/category"
                R.id.cart -> "/shop/cart"
                R.id.mine -> "/shop/mine"
                else -> "/shop/home"
            }).navigation() as Fragment).commit()
            true
        }
        binding.navigation.selectedItemId = R.id.home
    }
    @Event("购物车数量")
    fun cartNumberChange(n:Int) {
        val badge = binding.navigation.getOrCreateBadge(R.id.cart)
        badge.isVisible = n != 0
        badge.number = n
    }
}